package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.SyncRepayDetailDiffLogDao;
import com.fdb.efp.nls.service.domain.SyncRepayDetailDiffLog;
import com.fdb.efp.nls.service.facade.SyncRepayDetailDiffLogService;
import com.fdb.efp.nls.service.vo.SyncRepayDetailDiffLogVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 还款明细差异表服务实现
 *
 * @author gcb
 * @date 2020-04-27
 */
@Service("syncRepayDetailDiffLogService")
public class SyncRepayDetailDiffLogServiceImpl implements SyncRepayDetailDiffLogService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(SyncRepayDetailDiffLogServiceImpl.class);

    @Autowired
    private SyncRepayDetailDiffLogDao syncRepayDetailDiffLogDao;

    /**
     * 新增数据
     *
     * @param syncRepayDetailDiffLogVo
     * @return
     */
    @Override
    public int insert(SyncRepayDetailDiffLogVO syncRepayDetailDiffLogVo) {
        logger.debug("当前新增数据为:" + syncRepayDetailDiffLogVo.toString());
        int num = 0;
        try {
            SyncRepayDetailDiffLog syncRepayDetailDiffLog = new SyncRepayDetailDiffLog();
            beanCopy(syncRepayDetailDiffLogVo, syncRepayDetailDiffLog);
            num = syncRepayDetailDiffLogDao.insert(syncRepayDetailDiffLog);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param syncRepayDetailDiffLogVo
     * @return
     */
    @Override
    public int deleteByPk(SyncRepayDetailDiffLogVO syncRepayDetailDiffLogVo) {
        logger.debug("当前删除数据条件为:" + syncRepayDetailDiffLogVo);
        int num = 0;
        try {
            SyncRepayDetailDiffLog syncRepayDetailDiffLog = new SyncRepayDetailDiffLog();
            beanCopy(syncRepayDetailDiffLogVo, syncRepayDetailDiffLog);
            num = syncRepayDetailDiffLogDao.deleteByPk(syncRepayDetailDiffLog);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + syncRepayDetailDiffLogVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param syncRepayDetailDiffLogVo
     * @return
     */
    @Override
    public int updateByPk(SyncRepayDetailDiffLogVO syncRepayDetailDiffLogVo) {
        logger.debug("当前修改数据为:" + syncRepayDetailDiffLogVo.toString());
        int num = 0;
        try {
            SyncRepayDetailDiffLog syncRepayDetailDiffLog = new SyncRepayDetailDiffLog();
            beanCopy(syncRepayDetailDiffLogVo, syncRepayDetailDiffLog);
            num = syncRepayDetailDiffLogDao.updateByPk(syncRepayDetailDiffLog);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + syncRepayDetailDiffLogVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inSyncRepayDetailDiffLogVo
     * @return
     */
    @Override
    public SyncRepayDetailDiffLogVO queryByPk(SyncRepayDetailDiffLogVO inSyncRepayDetailDiffLogVo) {
        logger.debug("当前查询参数信息为:" + inSyncRepayDetailDiffLogVo);
        try {
            SyncRepayDetailDiffLog querySyncRepayDetailDiffLog = new SyncRepayDetailDiffLog();
            beanCopy(inSyncRepayDetailDiffLogVo, querySyncRepayDetailDiffLog);
            SyncRepayDetailDiffLog queryRslSyncRepayDetailDiffLog = syncRepayDetailDiffLogDao.queryByPk(querySyncRepayDetailDiffLog);
            if (Objects.nonNull(queryRslSyncRepayDetailDiffLog)) {
                return beanCopy(queryRslSyncRepayDetailDiffLog, new SyncRepayDetailDiffLogVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int batchInsert(List<SyncRepayDetailDiffLogVO> list) throws Exception {
        return this.syncRepayDetailDiffLogDao.batchInsert((List<SyncRepayDetailDiffLog>) beansCopy(list, SyncRepayDetailDiffLog.class));
    }
}
